package crm.model.teacherPC.net;

import java.awt.Image;
import java.net.Socket;
import java.util.ArrayList;

import crm.model.teacherPC.Manager;
import crm.model.teacherPC.matnr.MatNr;
import crm.model.teacherPC.statistic.Statistic;

public class StudentPC {

	private final Transfer transfer;
	private boolean isLocked;
	private String user;
	ArrayList<PcWindow> windowList;
	private Image screenshot;
	private final Socket socket;
	public final Statistic statistic;
	private String foreGroundWindow;
	public StudentPC(Socket socket, Manager manager) {
		this.socket=socket;
		transfer = new Transfer(socket, manager, this);
		statistic = new Statistic(this);
		transfer.getUser();
		transfer.getWindowName();
		windowList = new ArrayList<PcWindow>();
		isLocked = false;
		foreGroundWindow = "";
	}
	public void setBrowserCloseOn(boolean b){
		transfer.closeBrowser = b;
	}

	public String getUser() {
		return user;
	}
	public void setUser(String userName){
		if (MatNr.map.containsKey(userName.toUpperCase())){
			user = MatNr.map.get(userName.toUpperCase()).vName + " " + MatNr.map.get(userName.toUpperCase()).nName ;
		}else{
			user = userName;
		}
	}

	public Image getScreenshot() {
		return screenshot;
	}
	public void refreshScreenShot() {
		if (!isLocked){
			transfer.getImage();
		}
	}

	public synchronized void setMousePos(int x, int y) {
		transfer.setCursorPos(x, y);
	}

	public synchronized ArrayList<PcWindow> getWindows(){
		return windowList;
	}
	public synchronized void refreshWindows(){
		if (!isLocked){
			transfer.getWindowName();
		}
	}
	public void setWindows(ArrayList<PcWindow> windowList){
		this.windowList = windowList;
	}
	public synchronized void lockScreen(){
		isLocked = true;
		transfer.lockScreen();
	}
	public synchronized void unlockScreen(){
		isLocked = false;
		transfer.unLockScreen();
	}

	public synchronized void sendMessage(String message) {
		transfer.sendMessage(message);
	}
	public synchronized void closeConnection(){
		transfer.close();
	}

	public synchronized boolean isConnected() {
		return socket.isConnected();
	}
	@Override
	public synchronized String toString() {
		// TODO Auto-generated method stub
		return getUser();
	}
	public synchronized void refreshForegroundWindowName(){
		transfer.getForegroundWindowName();
	}
	public synchronized void setForegroundWindowName(String foregroundwindow){
		this.foreGroundWindow = foregroundwindow;
	}
	public String getForegroundWindowName(){
		return foreGroundWindow;
	}
	public void refreshStatistic() {
		statistic.refresh();
	}
	public String getIP(){
		return transfer.getIP();
	}
	public void setAppCloseOn(boolean b) {
		transfer.closeApp = b;
		
	}
	public void setScreenshot(Image screenShot) {
		this.screenshot = screenShot;

	}
}
